//
//  GQHomeKeyBoardToolBar.m
//  GuQu
//
//  Created by HELIUM STAR on 15/5/12.
//  Copyright (c) 2015年 HELIUM STAR. All rights reserved.
//

#import "GQHomeKeyBoardToolBar.h"
#define kToolMargin 10
#define kSmileWidth 30
#define kTextFieldHeight 30
#define kSendWidth 35

@interface GQHomeKeyBoardToolBar () <UITextFieldDelegate>

@end

@implementation GQHomeKeyBoardToolBar

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setUpKeyBoardToolBar];
    }
    return self;
}

- (void)setUpKeyBoardToolBar
{
    //创建表情按钮
    UIButton *btn = [[UIButton alloc] init];
    btn.x = kToolMargin;
    btn.width = kSmileWidth;
    btn.height = kSmileWidth;
    btn.y = (self.height - btn.width) / 2;
    [btn setBackgroundImage:[UIImage imageNamed:@"home_praise"] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:@"home_praised"] forState:UIControlStateSelected];
    [btn addTarget:self action:@selector(praiseBtnDidClick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn];
    
    //创建发送按钮
    
    UIButton *sendBtn = [[UIButton alloc] init];
    sendBtn.width = kSendWidth;
    sendBtn.height = 25;
    sendBtn.x = self.width - kToolMargin - kSendWidth;
    sendBtn.y = (self.height - sendBtn.height) / 2;
    
    [sendBtn setTitle:@"发送" forState:UIControlStateNormal];
    [sendBtn setTitleColor:[UIColor colorWithRed:55/255.0 green:185/255.0 blue:160/255.0 alpha:1.0] forState:UIControlStateNormal];
    sendBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [self addSubview:sendBtn];
    
    //创建输入框
    UITextField *textField = [[UITextField alloc] init];
    textField.x = CGRectGetMaxX(btn.frame) + kToolMargin;
    textField.width = self.width - 4 * kToolMargin - kSmileWidth - kSendWidth;
    textField.y = (self.height - kTextFieldHeight) / 2;
    textField.height = kTextFieldHeight;
    textField.placeholder = @"写评论";
    textField.layer.borderWidth = 1;
    textField.layer.borderColor = [UIColor lightGrayColor].CGColor;
    textField.backgroundColor = [UIColor whiteColor];
    textField.font = [UIFont systemFontOfSize:14];
    textField.delegate = self;
    self.textField = textField;
    
    textField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, textField.height)];
    textField.leftViewMode = UITextFieldViewModeAlways;
    [self addSubview:textField];
   
}

- (void)praiseBtnDidClick:(UIButton *)btn
{
    btn.selected = !btn.selected;
}


@end
